package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Registered;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.RegisteredService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class RegisteredController {

    @Autowired
    private RegisteredService registeredService;

    //路径变量参数
    //条件查询+分页
    @PostMapping("/registereds/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Registered>>
        getAllRegisteredById(@PathVariable("pageIndex") int pageIndex,
                             @PathVariable("pageSize") int pageSize,
                             @RequestBody Registered registered){
        System.out.println("查询条件："+registered);
        System.out.println("pageIndex："+pageIndex);
        System.out.println("pageSize："+pageSize);
        PageBean<Registered> pageBean= registeredService.getAllRegisteredById(registered,pageIndex,pageSize);
        ResponseResult<PageBean<Registered>> responseResult=
                new ResponseResult<>(200,"ok",pageBean);
        return responseResult;
    }

    //添加人员
    @PostMapping("/registereds")
    public ResponseResult addRestered(@RequestBody Registered registered){
        System.out.println("添加人员"+registered);
        registeredService.getinsert(registered);
        return new ResponseResult<>(200, "添加成功", null);
    }

    //修改人员
    @PutMapping("/registereds")
    public ResponseResult modifyRestered(@RequestBody Registered registered){
        System.out.println("修改人员"+registered);
        registeredService.getupdate(registered);
        return new ResponseResult<>(200, "修改成功", null);
    }

    //删除人员
    @DeleteMapping("/registereds/{rid}")
    public ResponseResult removeRestered(@PathVariable("rid") int rid){
        System.out.println("删除人员"+rid);
        registeredService.getdeleteById(rid);
        return new ResponseResult<>(200, "删除成功", null);
    }






}
